// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   MenuBar.java

package ui;

import java.io.IOException;
import java.io.PrintStream;
import java.util.Vector;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import mForms.MainFormss;

// Referenced classes of package ui:
//            BrowserCanvas, PageListener, Page

public class MenuBar
{
    private Image[] subImg;
    private Image hover;

    public MenuBar(String caption, PageListener listener, Vector submenu, Page src)
    {
        this.listener = listener;
        this.submenu = submenu;
        this.caption = caption;
        this.src = src;
        width = 0;
        height = 0;
        int hf = BrowserCanvas.FONTSMALL.getHeight();

        this.subImg = new Image[submenu.size()];

//        try {
//            this.hover = Image.createImage("/images/menu/mhover.png");
//        } catch (IOException ex) {
//            ex.printStackTrace();
//        }

////        for(int i = 0; i < submenu.size(); i++)
////        {
////
////            int x = i+1;
////            try {
////                this.subImg[i] = Image.createImage("/images/menu/mnu" + x + MainFormss.instance().lang+".png");
////                /*
////                height += hf;
////                int w = BrowserCanvas.FONTSMALL.stringWidth(submenu.elementAt(i).toString());
////                if(w > width)
////                width = w;
////                 *
////                 */
////            } catch (IOException ex) {
////                ex.printStackTrace();
////            }
//
//        }

        width += 8;
        shown = false;
    }

    public void draw(Graphics g, int x, int y, int w, int h)
    {
        g.setColor(BrowserCanvas.menuWarna1);
        y -= height;
        //g.fillRect(x - 1, y - 1, width + 10, height + 2);
        //g.drawRect(x - 2, y - 2, width + 10, height + 3);
        int hf = BrowserCanvas.FONTSMALL.getHeight();
        g.setFont(BrowserCanvas.FONTSMALL);

        g.setColor(0xFFFFFF);
        g.fillRect(0, (240 - 39 - (2*21)), 17, 240);

        for(int i = 0; i < submenu.size();)
        {
            if(i == selected)
            {
                int pohover = (240 - 39 - ((2-i)*21))+(this.subImg[i].getHeight()/2);

                g.drawImage(hover, 0, pohover, Graphics.VCENTER|Graphics.HCENTER);
                //g.setColor(BrowserCanvas.menuWarna2);
                //g.fillRect(x, y + 1, width + 8, hf);
            }
            //g.setColor(BrowserCanvas.menuWarna3);
            //g.drawString(submenu.elementAt(i).toString(), x + 2, y + 2, 20);
            int pb = (240 - 39 - ((2-i)*21));
            g.drawImage(this.subImg[i], 18, pb, Graphics.TOP|Graphics.LEFT);

            if(i > 0)
            {
                /*
                g.setColor(BrowserCanvas.menuWarna4);
                g.drawLine(x, y + 1, width + 13, y + 1);
                g.setColor(BrowserCanvas.menuWarna5);
                g.drawLine(x, y + 2, width + 13, y + 2);
                 * 
                 */
            }
            i++;
            y += hf;
        }

        //g.setColor(BrowserCanvas.menuWarna3);
    }

    public int keyPressed(int keycode)
    {
        if(keycode == BrowserCanvas.KEYDOWN)
        {
            if(selected < submenu.size() - 1)
                selected++;
            else
                selected = 0;
            return 4;
        }
        if(keycode == BrowserCanvas.KEYUP)
        {
            if(selected > 0)
                selected--;
            else
                selected = submenu.size() - 1;
            return 4;
        }
        if(keycode == BrowserCanvas.KEYCENTER || keycode == BrowserCanvas.KEYSOFTLEFT)
        {
            System.out.println("Selected Option : " + selected);
            try
            {
                listener.onMenu(src, selected, (String)submenu.elementAt(selected));
            }
            catch(ClassCastException er)
            {
                listener.onSoftLeftMenu(src, selected);
            }
            shown = false;
            return 3;
        }
        if(keycode == BrowserCanvas.KEYSOFTRIGHT)
        {
            shown = false;
            return 3;
        } else
        {
            return 0;
        }
    }

    public String toString()
    {
        return caption;
    }

    private Vector submenu;
    int width;
    int height;
    private int selected;
    boolean shown;
    public PageListener listener;
    private Page src;
    private String caption;
}
